function y = checkSample(sample)

% sample = [   470   508   148   406   476
%    404    71   406   404   106];

% 1st check: check outer shape (order, direction)
dAB = [sample(1,2)-sample(1,1);sample(2,2)-sample(2,1);0];

dAC = [sample(1,3)-sample(1,1);sample(2,3)-sample(2,1);0];

dAD = [sample(1,4)-sample(1,1);sample(2,4)-sample(2,1);0];

dBA = -dAB;

dBC = [sample(1,3)-sample(1,2);sample(2,3)-sample(2,2);0];

dBD = [sample(1,4)-sample(1,2);sample(2,4)-sample(2,2);0];

% 2nd check: check E inner point
% dAE = [sample(1,5)-sample(1,1);sample(2,5)-sample(2,1);0];
% dBE = [sample(1,5)-sample(1,2);sample(2,5)-sample(2,2);0];
% dCE = [sample(1,5)-sample(1,3);sample(2,5)-sample(2,3);0];
% dDE = [sample(1,5)-sample(1,4);sample(2,5)-sample(2,4);0];
% dCD = [sample(1,4)-sample(1,3);sample(2,4)-sample(2,3);0];
% dDA = -dAD;

a = cross(dAB,dAC);
b = cross(dAB,dAD);
c = cross(dBC,dBA);
d = cross(dBC,dBD);

% check E in (A,B,C,D)
% e = cross(dAB,dAE);
% f = cross(dBC,dBE);
% g = cross(dCD,dCE);
% h = cross(dDA,dDE);

ptx = sample(1,1);
pty = sample(2,1);
Ax = sample(1,4); 
Ay = sample(2,4);
Bx = sample(1,3);
By = sample(2,3);
h1 = abs((Bx-Ax)*(Ay-pty) - (Ax-ptx)*(By-Ay))/sqrt((Bx-Ax)^2 + (By-Ay)^2);
Area = h1*norm([Ax-Bx Ay-By 0]);

% if(a(3,1)<0)&&(b(3,1)<0)&&(c(3,1)<0)&&(d(3,1)<0)&&(e(3,1)<0)&&(f(3,1)<0)&&(g(3,1)<0)&&(h(3,1)<0)&&(Area>50),
if(a(3,1)<0)&&(b(3,1)<0)&&(c(3,1)<0)&&(d(3,1)<0)&&(Area>50),
    y = 1;

else
    y = 0;
end

end